<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<script>
    /* todo
        1. 创建对象的语法糖
    */
    class Person {
        id;
        name;
        age;
        #gender;

        get gender() {
            return this.#gender;
        }

        set gender(gender) {
            this.#gender = gender;
        }

        constructor(id, name, age, gender) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.#gender = gender;
        }

        sayHello() {
            console.log(`大家好，我是${this.name}`);
        }

        static show() {
            console.log('我是静态方法');
        }
    }

    let person1 = new Person();
    person1.id = 1;
    person1.name = '张三';
    person1.age = 20;
    // person.#gender = '男'; // 私有属性不能直接访问
    person1.gender = '男';
    console.log(person1);
    person1.sayHello();
    let person2 = new Person(1, '李四', 30, '女');
    console.log(person2);
    person2.sayHello();
    Person.show();

    class Student extends Person {
        clazz;
        score;

        constructor(clazz, score) {
            super();
            this.clazz = clazz;
            this.score = score;
        }
    }

    let student = new Student('2班', 85);
    student.clazz = '1班';
    student.score = 90;
    console.log(student);

    class Dog {
        #name;
        #age;
        get name() {
            return this.#name;
        }
        set name(name) {
            this.#name = name;
        }
        get age() {
            return this.#age;
        }
        set age(age) {
            this.#age = age;
        }
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
    }
    let dog1 = new Dog('旺财', 3);
    let dog2 = new Dog('二旺财', 4);
    let dog3 = new Dog('三旺财', 5);
    console.log(dog1);
    console.log(dog2);
    console.log(dog3);

</script>

</body>
</html>